from django.shortcuts import redirect,render,HttpResponse

from app01 import models
from app01.utils.Bootstrap import BootStrapModelForm

class UpModelForm(BootStrapModelForm):
    bootstrap_exclude_fields = ['img']
    class Meta:
        model =models.City
        fields ="__all__"
def city_list(request):
    queryset = models.City.objects.all()


    return render(request,'city_list.html',{'queryset':queryset})

def city_add(request):
    """上传文件和数据"""
    title = "新建城市"
    if request.method == "GET":
        form = UpModelForm()
        return render(request, 'upload_model_form.html', {"form": form, "title": title})
    form = UpModelForm(data=request.POST, files=request.FILES)
    if form.is_valid():
        form.save()
        return redirect("/city/list/")
    return render(request, 'upload_model_form.html', {"form": form, "title": title})